
public class TheMessage {

	private String Message;
	private int Id;
	
	public TheMessage(String message, int id) {
		super();
		Message = message;
		Id = id;
	}
	
	public String getMessage() {
		return Message;
	}
	public void setMessage(String message) {
		Message = message;
	}
	public int getId() {
		return Id;
	}
	public void setId(int id) {
		Id = id;
	}
	
	public int CountWords()
	{
		String temp=Message;
		int iEnd=0;
		int Num=0;
		do
		{
			iEnd=temp.indexOf(" ");
			System.out.println("iEnd "+iEnd);
			if(iEnd==-1)
				break;
			Num++;
			temp=temp.substring(iEnd+1, temp.length());
		}
		while(true);
		return Num+1;
	}
		
	public TheMessage Trunk()
	{
		if(Message.length()>15)
		{		
			int iBegin=Message.indexOf(" ",15);
			if(iBegin==-1)
				return null;
			int iEnd=Message.indexOf(" ", iBegin);
			if(iEnd==-1)
				return null;			
			TheMessage temp=new TheMessage(Message.substring(iBegin), Id);
			Message=Message.substring(0, iBegin);
			return temp;
		}
		return null;
	}
}
